package com.iflytek.ci.cums.service.impl;

import java.util.List;

import com.iflytek.ci.cpms.dao.TeamAccountMapDao;
import com.iflytek.ci.cpms.dao.TeamDao;
import com.iflytek.ci.cpms.domain.Team;
import com.iflytek.ci.cums.domain.Account;
import com.iflytek.ci.cums.service.TeamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service("TeamService")
@Transactional(readOnly = true,isolation = Isolation.READ_UNCOMMITTED)
public class TeamServiceImpl implements TeamService{
   
	@Autowired
	private TeamDao teamDao; 
	@Autowired
	private TeamAccountMapDao team_userDao;
	
	@Override
	public Team get_teamById(long id) {
		return teamDao.get_teamById(id);
	}

	@Transactional
	@Override
	public void remove_team(long id) {
		teamDao.remove_team(id);
        team_userDao.remove_teamAccountMap(id);
	}

	@Transactional
	@Override
	public void remove_team_with_projects(String[] project_ids) {
		teamDao.remove_team_with_project(project_ids);
        team_userDao.remove_team_with_projects(project_ids);
	}

    @Transactional
    @Override
    public long getTidByName(String tname) {
       return teamDao.getTidByName(tname);
    }

	@Transactional(propagation = Propagation.REQUIRED)
	@Override
	public void add_team(Team team,long[] uid) {
		if (team.getId() == 0) {
			team.setSize(uid.length);
			teamDao.add_team(team);
			//设置团队成员
			team_userDao.add_teamAccountMap(team.getId(), uid);
		} else {
			//增加 团队成员
			team_userDao.remove_teamAccountMap(team.getId());
			//设置团队成员
			team.setSize(uid.length);
			//设置团队成员
			team_userDao.add_teamAccountMap(team.getId(), uid);
		}

	}

	@Override
	public List<Account> get_unameby_tid(long team_id) {
		return teamDao.get_unameby_tid(team_id);
	}

}
